/*
 * @(#)LoadBalancer.java   1.0  2021年9月10日
 * 
 * Copyright (c)	2014-2020. All Rights Reserved.	GuangZhou hhmk Technology Company LTD.
 */
package com.swift.api.aliyun.client;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.aliyun.slb20140515.Client;
import com.aliyun.teaopenapi.models.Config;
import com.swift.exception.extend.SystemException;
import com.swift.util.type.TypeUtil;

/**
 * 通用參数调用 
 * @author zhengjiajin
 * @version 1.0 2021年9月10日
 */
@Component
public class ClbClient {
    @Value("${aliyun.AccessKey:}")
    private String accessKey;
    
    @Value("${aliyun.SecretKey:}")
    private String secretKey;
    
    @Value("${aliyun.RegionId:}")
    private String regionId;

    private Client client;
    
    @PostConstruct
    private void init() {
        if(TypeUtil.isNull(accessKey)) return;
        if(TypeUtil.isNull(secretKey)) return;
        if(TypeUtil.isNull(regionId)) return;
        Config config = new Config().setAccessKeyId(accessKey).setAccessKeySecret(secretKey).setRegionId(regionId);
        try {
            client = new Client(config);
        } catch (Exception e) {
            new SystemException("阿里客户端连接SLB失败");
        }
    }
    
    public Client getClient() {
        if(client==null) new SystemException("阿里客户端未创建");
        return client;
    }
    
}
